import { Commit } from 'vuex'
import storage from '@/utils/storage'
export default {
  namespaced: true,
  state: {
    WordVisble: false, // 话术弹框
    isNewWord: true, //是否是新建话术
    depart: {
      creaters: [], // 创建人信息
      isMember: true, // 部门选择是否只能选人员信息
      departVisble: false, //部门弹框
      title: '设置部门负责人', //部门标题
    },
    tagsInfo: {
      EditTags: false, //编辑标签
      tags: [], // 选中标签信息
      TagsVisble: false, // 标签弹框,
      showCreatTag: false, // 是否新建标签
      batchTag: false, // 是否是批量
      title: '选择标签', // 标签标题
    },
    type: 0,// 1-文本 2-图片 3-音频 4-视频 5-文件 6-链接文章 7-链接引用
    // 上传弹框
    upload: {
      uploadVisib: false,
      title: '上传文本',
      type:""
    },
    // 分组管理
    group: {
      groupId: 0, //分组id
      groupList: [] || storage.get('groupList')
    }
  },
  mutations: {
    WORD_ART_DIALOG: (state: any, data: boolean) => {
      state.WordVisble = data;
    },
    IS_NEW_WORD: (state: any, data: boolean) => {
      state.isNewWord = data;
    },
    DE_PART: (state: any, data: any) => {
      state.depart = {
        ...state.depart,
        ...data,
      }
    },
    TAGS_INFO: (state: any, data: any) => {
      state.tagsInfo = {
        ...state.tagsInfo,
        ...data,
      }
    },
    CHANGE_TYPE: (state: any, data: number) => {
      state.type = data;
    },
    UPLOAD: (state: any, data: any) => {
      state.upload = {
        ...state.upload,
        ...data,
      }
    },
    GROUP: (state: any, data: any) => {
      state.group = {
        ...state.group,
        ...data
      }
      storage.set('groupList', state.group.groupList)
    }
  },
  actions: {
    openWordArt: (context: { commit: Commit }, data: boolean) => {
      context.commit('WORD_ART_DIALOG', data)
    },
    isNewWord: (context: { commit: Commit }, data: boolean) => {
      context.commit('IS_NEW_WORD', data)
    },

    depart: (context: { commit: Commit }, data: any) => {
      context.commit('DE_PART', data)
    },
    tagsInfo: (context: { commit: Commit }, data: any) => {
      context.commit('TAGS_INFO', data)
    },
    changeType: (context: { commit: Commit }, data: number) => {
      context.commit('CHANGE_TYPE', data)
    },
    upload: (context: { commit: Commit }, data: any) => {
      context.commit('UPLOAD', data)
    },
    group: (context: { commit: Commit }, data: any) => {
      context.commit('GROUP', data)
    },
  },
  getters: {
    openWordArt: (state: any) => state.WordVisble,
    isNewWord: (state: any) => state.isNewWord,
    depart: (state: any) => state.depart,
    tagsInfo: (state: any) => state.tagsInfo,
    type: (state: any) => state.type,
    upload: (state: any) => state.upload,
    group: (state: any) => state.group,
  }
}